#!/usr/bin/python
# author Yu
# 2023年03月08日
from itertools import count

from django.db import connection
from django.db.models import Count

from post.models import *


def getRightInfo(request):
    # 1.获取分类信息
    r_catepost = Post.objects.values('category__cname','category').annotate(c=Count('*')).order_by('-c')
    # 近期文章
    r_recentpost = Post.objects.order_by('-created')[:3]
    # 归档
    cursor=connection.cursor()
    cursor.execute("SELECT YEAR(created) AS year, MONTH(created) AS month, COUNT(*) AS count FROM t_post GROUP BY year, month")
    file_post= cursor.fetchall()
    return {'cate_post': r_catepost, 'recentpost': r_recentpost,'file_post':file_post}
